import type { FormSchema } from '@/components/core/schema-form/';
import dayjs from 'dayjs';

// 延期申请单表单数据
export const extensionschemas: FormSchema[] = [
  {
    field: 'id',
    component: 'Input',
    colProps: {
      span: 0,
    },
    componentProps: {
      hidden: true,
    },
  },
  {
    field: 'expirationTime',
    component: 'Input',
    colProps: {
      span: 0,
    },
    componentProps: {
      hidden: true,
    },
  },
  {
    field: 'extensionNo',
    component: 'Input',
    label: '延期单号',
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'estimatedCompletionTime',
    component: 'DatePicker',
    label: '预计完成时间',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 12,
    },
    componentProps: ({ formModel }) => {
      return {
        min: formModel.expirationTime,
        style: {
          width: '100%',
        },
        disabledDate: (current) => {
          return (
            current && current < dayjs(formModel.expirationTime).endOf('day').subtract(1, 'day')
          );
        },
        disabledTime: (dates) => {
          if (
            dayjs(formModel.expirationTime).format('YYYY/MM/DD') ==
            dayjs(dates).format('YYYY/MM/DD')
          ) {
            return {
              disabledHours: () => range(0, dayjs(formModel.expirationTime).hour()),
              disabledMinutes: () => range(0, dayjs(formModel.expirationTime).minute()),
              disabledSeconds: () => range(0, dayjs(formModel.expirationTime).second()),
            };
          }
        },
        showTime: true,
        valueFormat: 'YYYY-MM-DD HH:ss:mm',
      };
    },
  },
  {
    field: 'extensionReason',
    component: 'InputTextArea',
    label: '延期原因',
    componentProps: {
      rows: 6,
    },
    rules: [
      { required: true, type: 'string' },
      { max: 10000, message: '延期原因不能大于5000个字' },
    ],
    colProps: {
      span: 24,
    },
  },
  {
    field: 'filledBy',
    component: 'Input',
    label: '填报人',
    rules: [{ required: false, type: 'string' }],
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'filledTime',
    component: 'Input',
    label: '填报时间',
    rules: [{ required: false, type: 'string' }],
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true,
    },
  },
];


const range = (start: number, end: number) => {
  const result: number[] = [];
  for (let i = start; i < end; i++) {
    result.push(i);
  }

  return result;
};
